from abc import ABC, abstractmethod
from typing import Optional, Dict, Any, List
import json
from utils.Logger import Logger

class AIServiceBase(ABC):
    def __init__(self, api_key: str, config: Dict = None):
        self.logger = Logger(self.__class__.__name__)
        self.api_key = api_key
        self.config = config or {}
        self.logger.info(f"{self.__class__.__name__} initialized")

    def get_model_params(self) -> Dict[str, Any]:
        """获取模型参数"""
        return {
            "temperature": self.config.get("temperature", 0.7),
            "top_p": self.config.get("top_p", 0.9),
            "max_tokens": self.config.get("max_tokens", 1000)
        }

    @abstractmethod
    async def generate_text(self, prompt: str) -> Optional[str]:
        """生成文本"""
        pass

    @abstractmethod
    async def continue_writing(self, text: str) -> Optional[str]:
        """续写文本"""
        pass

    @abstractmethod
    async def ask_question(self, question: str) -> Optional[str]:
        """回答问题"""
        pass

    @abstractmethod
    async def expand_text(self, text: str) -> Optional[str]:
        """扩写文本"""
        pass

    @abstractmethod
    async def analyze_code(self, code: str) -> Optional[Dict[str, Any]]:
        """分析代码"""
        pass

    @abstractmethod
    async def summarize_text(self, text: str, max_length: int = 150) -> Optional[str]:
        """文本摘要"""
        pass

    @abstractmethod
    async def translate_text(self, text: str, target_language: str = "en") -> Optional[str]:
        """文本翻译"""
        pass

    @abstractmethod
    async def convert_style(self, text: str, target_style: str = "informal") -> Optional[str]:
        """风格转换"""
        pass
